import java.util.ArrayList;
import java.util.List;

public class SolutionInterview16_26 {
    public int calculate(String s) {
        s=s.replaceAll(" ","");
        int count=0;
        List<Integer> numbers=new ArrayList<>();
        List<Character> chars=new ArrayList<>();
        while (count<s.length()){
            if (s.charAt(count)>='0' && s.charAt(count)<='9') {
                int current = 0;
                while (count < s.length() && s.charAt(count) >= '0' && s.charAt(count) <= '9') {
                    current = current * 10 + s.charAt(count) - '0';
                    count++;
                }
                numbers.add(current);
            }else{
                chars.add(s.charAt(count));
                count++;
            }
        }
        List<Integer> stack=new ArrayList<>();
        stack.add(numbers.get(0));
        for (int i=0;i<chars.size();i++){
            if (chars.get(i)=='/'||chars.get(i)=='*'){
                int t=stack.remove(stack.size()-1);
                int m=numbers.get(i+1);
                int p=chars.get(i)=='/'?t/m:t*m;
                stack.add(p);
            }else{
                stack.add(numbers.get(i+1));
            }
        }
        int ans=stack.get(0);
        int t=1;
        for (Character aChar : chars) {
            if (aChar == '+' || aChar == '-') {
                ans = aChar == '+' ? ans + stack.get(t) : ans - stack.get(t);
                t++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview16_26().calculate("3+2*2"));
    }
}
